#制作ini配置文件
import configparser

def write_ini():
    try:
        config = configparser.ConfigParser()
        config.read("WebConfig.ini", encoding='utf-8')
        config.add_section("SET")
        config.set("SET", "easyhost", "nbaxx")
        config.set("SET", "host", "www.nbaxx.com")
        config.set("SET", "allhost", "http://www.nbaxx.com")
        config.set("SET", "username", "xiaojiejie")
        config.set("SET", "password", "xiaojiejie")
        config.set("SET", "email", "xiaojiejie@163.com")
        config.set("SET", "title", "我是标题{keyword}")
        config.set("SET", "content", "我是内容{keyword}")
        config.set("SET", "info", "我是个人主页{keyword}")
        config.write(open("WebConfig.ini", "w", encoding='utf-8'))
    except configparser.DuplicateSectionError:
        print("Section 'SET' already exists")

write_ini()
def read_ini():
    class postinfo:
        easyhost=''
        host=''
        allhost=''
        username=''
        password=''
        email=''
        title=''
        content=''
        info=''
    try:
        config = configparser.ConfigParser()
        config.read("WebConfig.ini", encoding='utf-8')
        postinfo.easyhost = config.get("SET", "easyhost")
        postinfo.host = config.get("SET", "host")
        postinfo.allhost = config.get("SET", "allhost")
        postinfo.username = config.get("SET", "username")
        postinfo.password = config.get("SET", "password")
        postinfo.email = config.get("SET", "email")
        postinfo.title = config.get("SET", "title")
        postinfo.content = config.get("SET", "content")
        postinfo.info = config.get("SET", "info")
        return postinfo
    except Exception as e:
        print("Section 'SET' NOT exists")
        return None
read_ini()